package model

import (
	"fmt"
	"leaf/cache"
	"leaf/core/tool"
	"leaf/pb"
)

type UserModel struct {
	User *pb.DbUser
}

func NewUserModel(userid uint64) *UserModel {
	m := &UserModel{
		User: &pb.DbUser{},
	}
	key := fmt.Sprintf(cache.GAMER_USER, cache.GetKeyPrefix(), userid)

	var data, err = cache.GetCache().Get(key).Result()
	if err != nil {
		return nil
	}

	if !tool.ParseDBStr(data, m.User) {
		return nil
	}

	return m
}

func (m *UserModel) Save(save bool) bool {
	//key := fmt.Sprintf(GAMER_USER, GetKeyPrefix(), m.User.GetUserid())
	//if err := GetInstance().Setx(key, m.User, save); err != nil {
	//	return false
	//}
	return true
}
